<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        //1.将数字型转换为字符串型的两种方法 变量.toString()
        var num = 10
        var str = num.toString()
        console.log(str,typeof(str))
        //利用 String(变量名)
        console.log(String(num))

        //2.将其他类型数据转换为数字型 4种方法
        var age = '18'
        console.log(parseInt(age))
        console.log(Number(age))
        console.log(parseInt('120px')) //120
        console.log(parseFloat('3.14'))
        //第4种，利用隐式转换
        console.log('12' - 0)
        console.log('123' - '120')
        console.log('123' * 1)

        //3.转换为布尔型
        console.log(Boolean('你好'))
        console.log(Boolean(1))
        

        //计算岁数案例
        var myDate = new Date()
        var year = myDate.getFullYear() //获取当前年
        birth = prompt('请输入您的出生年份:')
        age = year - birth
        alert('您今年已经' + age + '岁')
        console.log('您今年已经' + age + '岁')
        
    </script>
</head>
<body>
    
</body>
</html>